<?php

namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\DepositOrder;
use app\common\model\TeacherOrder as TeacherOrderModel;

class Deposit extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    public function add_order()
    {
        $params = $this->request->post();
        $order = DepositOrder::addOrder($params);
        $this->success('订单添加成功', $order);
    }

    //教师-预接单，判断该教师是否需要额外支付押金
    public function prepre_accept()
    {
        $param = $this->request->param();
        $user_id = $this->auth->id;

        $order = TeacherOrderModel::where([
            'id'=>$param['order_id'],
            'teacher_id'=>$user_id,
            'status'=>1
        ])->find();
        if(!$order){
            $this->error('订单不存在');
        }

        $need_pay_deposit = false;//是否需要支付押金
        $need_pay_agency = false;//是否需要支付中介费
        if($order['pay_agency']==0){
            $need_pay_agency = true;
        }

        $nbnormal_order = TeacherOrderModel::where([
            'teacher_id'=>$user_id,
            'abnormal' => ['neq','']
        ])->find();
        if($nbnormal_order && $order['pay_deposit']==0){
            $need_pay_deposit = true;
        }
        $this->success('预接单详情',[
            'need_pay_deposit'=>$need_pay_deposit,
            'need_pay_agency'=>$need_pay_agency
        ]);
    }

}